let app = getApp();
export default {
	data() {
		return {
			//设置默认的分享参数
			//如果页面不设置share，就触发这个默认的分享
			share: {
				title: "拾亲-让全球华人有家谱",
				url: '/pages/tabBar/home/index',
				desc: '',
				imageUrl: "",
				content: "",
				// 分享类型，1截图分享，0轮播图片分享
				shareType: 0,
			},
		}
	},
	onShareAppMessage(res) { //分享到微信朋友
		var xing = uni.getStorageSync("shiqin-user-xing")
		var ming = uni.getStorageSync("shiqin-user-ming")
		var user = uni.getStorageSync("shiqin-user")
		console.log(JSON.stringify(res))
		// 设置分享图片
		if (this.share.shareType == 1) {
			//非专属页面
			var shareImgIndex = uni.getStorageSync("global-share-img-index")
			if (shareImgIndex) {
				switch (shareImgIndex % 3) {
					case 0:
						this.share.imageUrl = "https://c.shiqin.wang/xiao.jpg"
						break;
					case 1:
						this.share.imageUrl = "http://c.shiqin.wang/photo/xiaoyi.jpg"
						break;
					case 2:
						this.share.imageUrl = "http://c.shiqin.wang/photo/xiaoer.jpg"
						break;
				}
				uni.setStorageSync("global-share-img-index", shareImgIndex + 1)
			} else {
				this.share.imageUrl = "https://c.shiqin.wang/xiao.jpg"
				uni.setStorageSync("global-share-img-index", 1)
			}
			// 设置登陆标题
			if (user.PQD) {
				var mobile = user.mobile.substr(0, 3) + '****' + user.mobile.substr(7, 11);
				this.share.title = "拾亲家谱代言人:" + xing + ming + mobile
			} else {
				this.share.title = "拾亲-让全球华人有家谱"
			}
		} else {
			//专属页面
			this.share.imageUrl = ""
		}
		var reg = new RegExp("(^|\\?|&)treeId=([^&]*)(\\s|&|$)", "i");
		var treeId;
		if (reg.test(this.share.url)) {
			treeId = unescape(RegExp.$2.replace(/\+/g, " "));
			uni.setStorageSync("tree-number-count-limit_" + treeId, 1)
		}
		return {
			title: this.share.title,
			path: this.share.url,
			imageUrl: this.share.imageUrl,
			desc: this.share.desc,
			content: this.share.content,
		}
	},

}
